/*
 * @Description: ջ
 * @Author: zhangbo
 * @Date: 2021-03-29 20:23:32
 * @LastEditTime: 2021-04-07 20:36:20
 * @LastEditors: zhangbo
 */
#include "Stack.h"
#include <iostream>
using namespace std;

template <class T>
void Stack<T>::Clear()
{
    Size = 0;
    Node *p;
    while (top != nullptr)
    {
        p = top;
        top = top->next;
        delete p;
    }
}

template <class T>
int Stack<T>::size() const
{
    return Size;
}

template <class T>
void Stack<T>::push(const T &value)
{
    Node *p = new Node(value, top);
    top = p;
    Size++;
}

template <class T>
T Stack<T>::pop()
{
    if (this->empty())
    {
        cout << "Stack is empty,Don`t Pop it!!!" << endl;
        return 0;
    }
    Node *p = top;
    T val = p->val;
    top = top->next;
    delete p;
    Size--;
    return val;
}

template <class T>
T Stack<T>::Top() const
{
    if (this->empty())
    {
        cout << "Stack is empty,No Top item!!!" << endl;
        return 0;
    }
    return top->val;
}

template <class T>
Stack<T> Convert(int &n, const int &k)
{
    Stack<int> res;
    while (n != 0)
    {
        res.push(n % k);
        n /= k;
    }
    return res;
}